﻿using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using com.IronOne.BoardPACWinAppService.Auth;

// The Settings Flyout item template is documented at http://go.microsoft.com/fwlink/?LinkId=273769

namespace com.IronOne.BoardPACWinApp.View.UserControl
{
    public sealed partial class SupportFlyout
    {
        private IAuthService _authService;

        public SupportFlyout()
        {
            InitializeComponent();
            _authService = new AuthService();

            CopyrightTextBlock.Text = DateTime.Now.Year + " IronOne Technologies (Pvt) Ltd.";
        }

        private async void SettingsFlyout_Loaded(object sender, RoutedEventArgs e)
        {
            var mod = await _authService.GetSupportInfoFromDb();
            if (mod == null) return;

            if (!String.IsNullOrWhiteSpace(mod.SupportInfoName))
                ContactInfoTextBlock.Text = mod.SupportInfoName;
            if (!String.IsNullOrWhiteSpace(mod.SupportInfoDisplayPhones))
                TelephoneInfoTextBlock.Text = mod.SupportInfoDisplayPhones;
            if (!String.IsNullOrWhiteSpace(mod.SupportInfoDisplayEmails))
                EmailInfoTextBlock.Text = mod.SupportInfoDisplayEmails;
        }

        private void SettingsFlyout_Unloaded(object sender, RoutedEventArgs e)
        {
            _authService = null;
        }
    }
}